package com.destinomusical.epura.adapter;


import com.smartthinking.destinomusical.R;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridAdapter extends BaseAdapter {
	private Context mContext;
	Resources res;
	String[] title;
	TypedArray icons;
	LayoutInflater inflater;

	public GridAdapter(Context c, 
					   String[] title, 
					   TypedArray icons) {
		mContext = c;
		res = c.getResources();
		this.title = title;
		this.icons = icons;
		inflater = (LayoutInflater) mContext
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return icons.length();
	}

	@Override
	public Object getItem(int arg0) {
		return title[arg0];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		ViewHolder holder;
		if (vi == null) {
			holder = new ViewHolder();
			vi = inflater.inflate(R.layout.griditem_catego, null);
			holder.image = (ImageView) vi.findViewById(R.id.image);
			holder.text = (TextView) vi.findViewById(R.id.text);
			vi.setTag(holder);
		}

		holder = (ViewHolder) vi.getTag();
		holder.image.setImageDrawable(icons.getDrawable(position));
		holder.text.setText(title[position]);
		return vi;

	}

	public class ViewHolder {
		public ImageView image;
		public TextView text;
	}

}
